<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/tags.jsp" %>
<!doctype html><!-- 此处doctype不能去掉，否则amaze样式会有奇怪问题 -->
<html class="no-js">
<head>
    <meta charset="utf-8">
    <title>编辑</title>
    <%@ include file="/common/amaze_meta.jsp" %>
</head>
<body>
<section data-am-widget="accordion" class="am-accordion am-accordion-gapped"
data-am-accordion='{  }'>
  <dl class="am-accordion-item am-active">
    <dt class="am-accordion-title"><span class="am-icon-search"></span> 查询</dt>
    <dd class="am-accordion-bd am-collapse am-in">
      <!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题， 加一个容器 -->
      <div class="am-accordion-content">
		<form id="_searchForm">
			<input type="hidden" name="pageNo" value="${param.pageNo}"/>
			<input type="hidden" name="mid" value="${param.mid}"/>
        <div class="search_tab" style="overflow:auto;">
        	<div class="tr">
        		<div class="label">名称</div>
				<div class="value">
				<input type="text" name="name" class="am-form-field am-radius" value="${param.name}">
				</div>
        		<div class="label">是否推荐</div>
        		<div class="value">
					<select name="recommend">
						<option value="">请选择...</option>
						<option value="1">是</option>
						<option value="0">否</option>
					</select>
        		</div>
				<div class="label">商家名称</div>
				<div class="value">
					<input type="text" name="sellerName" class="am-form-field am-radius" value="${param.sellerName}">
				</div>
        	</div> 
        	<div class="tr">        		
        		<div class="label">上传时间</div>
        		<div class="value" style="width:60%">
        			<input type="text" name="date_s" class="am-form-field am-date" placeholder="" data-am-datepicker readonly/>
        			--
        			<input type="text" name="date_e" class="am-form-field am-date" placeholder="" data-am-datepicker readonly/>
        		</div>
        	</div>       	  
        	<div class="btn"><button type="button" class="am-btn am-btn-success" onclick="_search()">查询</button></div>
        </div>
		</form>
      </div>
    </dd>
  </dl>
  </section>

<%--<div class="am-g">
    <div class="am-u-md-6 am-cf">
        <div class="am-fl am-cf">
            <div class="am-btn-toolbar am-fl">
                <div class="am-btn-group am-btn-group-xs">
                    <button id="btn_view" type="button" type="button" class="am-btn am-btn-default"><span class="am-icon-search"></span> 查看详情</button>                    
                </div>
            </div>
        </div>
    </div>
</div>--%>

<div class="am-g">
<div class="am-u-sm-12">
<form class="am-form" action="a.html">
<table class="am-table am-table-striped am-table-hover table-main">
<thead>
<tr>
    <th class="table-check"><input type="checkbox" /></th>
    <th class="table-id">ID</th>
    <th class="table-title">名称</th>
    <th class="table-type">价格</th>
    <th class="table-author">商家</th>
	<th class="table-date">是否推荐</th>
    <th class="table-date">上传日期</th>
    <th class="table-set">操作</th>
</tr>
</thead>
<tbody id="pageList">

<c:forEach items="${pager.records}" var="item">
<tr id="goods_${item.id}">
    <td><input type="checkbox" /><input type="hidden" value="${item.id}"></td>
    <td>${item.id}</td>
    <td><a href="#">${item.name}</a></td>
    <td>${item.price}</td>
    <td>${item.sellername}</td>
	<td>
		<c:if test="${item.recommend==1}">是<a href="javascript:recommend(0,'${item.id}');">（取消）</a></c:if>
		<c:if test="${item.recommend==0}">否<a href="javascript:recommend(1,'${item.id}');">（推荐）</a></c:if>
	</td>
    <td>${item.create_time}</td>
  <td>
        <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
				<button type="button" class="am-btn am-btn-default" onclick="view(${item.id})"><span class="am-icon-search"></span> 查看详情</button>
				<button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger" onclick="deleteGoods('${item.id}')"><span class="am-icon-trash-o"></span> 删除</button>
            </div>
        </div>
    </td>
</tr>
</c:forEach>

</tbody>
</table>

<div id="kkpager"></div>
<script>
$(function(){
	ishop.kkpager(${pager.pageNo},${pager.pageCount},${pager.totalRecord},selectPage);
	$("select[name=recommend]").val(${param.recommend});
});
function selectPage(pageNo){
	$("input[type=hidden][name=pageNo]").val(pageNo);
	_search();
}

function _search(){
	var queryString = $('#_searchForm').formSerialize();
	var url ="${ctx}/admin/goods/ex/publish.do?publishState=1&"+queryString;
	location.href = url;
}
function recommend(rec,goodsId){
	if(confirm("确定操作？")){
		$.post("${ctx}/admin/goods/ex/recommend.do",{
			recommend:rec,
			id:goodsId
		},function(data){
			if(data.success){
				alert("操作成功！");
				location.reload();
			}
		},"json");
	}
}

function deleteGoods(goodsId){
	if(confirm("确定操作？")){
		$.post("${ctx}/admin/goods/ex/changeState.do",{
			state:0,
			id:goodsId
		},function(data){
			if(data.success){
				alert("操作成功！");
				$("#goods_"+goodsId).remove();
			}
		},"json");
	}
}



function view(goodsId){
	$.dialog({
		id:'view',
		title: '',
		type:1,
		width:500,
		height:450,
		url:'${ctx}/admin/goods/ex/view.do?id='+goodsId
	});
}
</script>

</form>

</div>

</div>
</body>
</html>
